package com.hb.resource.interceptor;



/**
 * @author hb
 * @date:2023/4/25 14:51
 */

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @Description kafka拦截器  统计数据量
 * @Author hb
 * @DateTime 2021/11/27
 */
public class CounterInterceptor implements ProducerInterceptor<String, String> {
    int success , error;
    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        return record;
    }

    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
        if (metadata != null) {
            success++;
        } else {
            error++;
        }
    }

    @Override
    public void close() {
        System.out.println(success);
        System.out.println(error);
    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
